Skip to content

Add Designate zone and recordset query - #9

Merged
Mohammed Naser (mnaser) merged 2 commits into
vexxhost:mainfrom
fitbeard:feat/designate-queries
Dec 1, 2026
Merged

Mohammed Naser (mnaser) merged 2 commits into
vexxhost:mainfrom
fitbeard:feat/designate-queries

Conversation

@fitbeard

@fitbeard Tadas Sutkaitis (fitbeard) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a typed, read-only Designate query for the database exporter. It returns zones and their recordsets in one query, retains zones with no recordsets, and excludes soft-deleted zones.

Recordset status follows Designate's API precedence (ERROR, PENDING, ACTIVE, DELETED) and defaults to ACTIVE when a recordset has no records. The PR includes the generated sqlc bindings, an embedded schema fixture, and integration coverage in tests/queries_test.go.

The exporter can use this query to produce its Designate metrics after updating its openstackdb dependency.

Verification

  • go test -count=1 -race ./...
  • go vet -tags integration ./...
  • go test -count=1 -tags integration -run '^$' ./...
  • sqlc diff with v1.30.0 and gofmt -l .
  • A read-only live exporter scrape returned one zone and three recordsets. A read-only SQL fixture verified status precedence, empty zones and recordsets, and soft-delete filtering.

Signed-off-by: Tadas Sutkaitis <tadas.sutkaitis@vexxhost.com>
@fitbeard
Tadas Sutkaitis (fitbeard) marked this pull request as ready for review December 1, 2026 08:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T08:49:58.870408Z ae9e756 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae9e7560fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread designate/db/queries.sql Outdated
Comment on lines +20 to +21
LEFT JOIN recordsets rs ON rs.zone_id = z.id
LEFT JOIN records r ON r.recordset_id = rs.id

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Exclude soft-deleted recordsets and records

When an active zone has child rows that Designate has soft-deleted, the recordsets and records tables retain them with a nonzero deleted marker, but these unconditional joins still include them. This causes deleted recordsets to remain in the result and lets historical records affect the MAX-based status, so exporter metrics become stale after ordinary recordset updates or deletions; add deleted = '0' predicates to both LEFT JOIN conditions (rather than WHERE, so empty zones remain visible) and model those columns in the fixture.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified the schema against a live Designate database. zones has deleted and deleted_at, but recordsets and records have neither column. Adding rs.deleted = '0' or r.deleted = '0' would make the query fail with an unknown-column error. Designate schema

Designate's storage helper issues a physical delete for tables without a deleted column. Deleting a recordset cascades to its records, and updating a recordset physically deletes records removed from it. The API also includes DELETED as a valid child status when computing recordset status, so the SQL preserves that precedence. Delete helper · Recordset update · Status calculation

The existing z.deleted = '0' predicate covers soft-deleted zones, and the LEFT JOINs preserve zones with zero recordsets.

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status precedence is right, but two things need to change before this merges: the ID format doesn't match what the API returns, and the single query makes it impossible to cheaply turn off the per-recordset metric.

Must fix

IDs come back in the wrong format. Designate stores every UUID column (zones.id, recordsets.id, recordsets.zone_id) as 32 hex characters without dashes and adds the dashes back when reading (types.py). This query returns the raw column, so the exporter's id and zone_id labels would read 3f2a… where upstream openstack-exporter has 3f2a…-…-…. ENG-423 needs the labels to match upstream so existing dashboards keep working. #117 on the exporter hit the same thing and added a formatUUID helper. I'd rather fix it here so every caller gets the API format, for example INSERT(INSERT(INSERT(INSERT(id,21,0,'-'),17,0,'-'),13,0,'-'),9,0,'-'), which works on both MySQL and MariaDB, or a small Go helper. The test fixture uses IDs like zone-1, which hides this; please use real 32-character hex IDs and assert the dashed output.

Split the query. ENG-423 asks for separate queries for zone details, recordset counts per zone, and recordsets with status. Doing it all in one join means the exporter pays for grouping every recordset with its records on every scrape, even if we put openstack_designate_recordsets_status behind a flag. Something like:

  • ZoneGetAll for zones and zone_status
  • a COUNT(*) ... GROUP BY zone_id over recordsets for recordsets
  • the records join only for recordsets_status

That also saves the exporter from deriving zone counts by skipping NULL recordset rows. In the status query, consider aggregating records by recordset_id in a derived table before joining, so MySQL isn't grouping on the wide name columns.

Looks good

  • The CASE/MAX precedence (ERROR, PENDING, ACTIVE, DELETED, and ACTIVE for no records) matches RecordSet.status in recordset.py.
  • Your reply to the Codex comment is correct: recordsets and records have no deleted column (tables.py), so z.deleted = '0' is the same filter the API applies.
  • The LEFT JOINs keep empty zones, which the per-zone count needs.

Minor

  • The fixture makes recordsets.zone_id nullable, but it's NOT NULL in Designate, which gives the generated model an unnecessary sql.NullString.
  • API.md has no Designate entry in the mapping table or the upstream references.

Signed-off-by: Tadas Sutkaitis <tadas.sutkaitis@vexxhost.com>

Tadas Sutkaitis (fitbeard) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Follow-up to the changes-requested review. The fixes are in 6baf0c3.

  • ZoneGetAll, RecordsetCountByZone, and RecordsetGetAllWithStatus now run independently and return dashed UUIDs. The per-zone count includes zero-count zones, and the status query aggregates child records by recordset_id before joining.
  • The integration fixture uses compact UUIDs and asserts dashed results. It exercises both upstream's NOT NULL recordsets.zone_id and the nullable variant observed on our 2025.1 deployment, including a recordset with a NULL zone ID. The API.md mapping now covers all three methods.
  • The local exporter follow-up verifies the intended consumer behavior. A read-only scrape on 2025.1 returned all five metrics with 3 zones and 15 recordsets. Disabling recordset status preserved the counts and skipped the status query. An unreachable database produced _up=0.

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both requested changes are in 6baf0c3: the queries are split, and IDs come back as dashed UUIDs with tests covering them. The NULL zone_id coverage for the 2025.1 schema is a good addition. Merging as a squash with the title updated to match the three queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants